<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 5.4.2">

  <link rel="apple-touch-icon" sizes="180x180" href="https://static.xiaosige.com/img/favicon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="https://static.xiaosige.com/img/favicon.png">
  <link rel="icon" type="image/png" sizes="16x16" href="https://static.xiaosige.com/img/favicon.png">
  <link rel="mask-icon" href="https://static.xiaosige.com/img/favicon.png" color="#222">
  <meta name="baidu-site-verification" content="WZilU4QiSZ">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.31/dist/fancybox/fancybox.css" integrity="sha256-gkQVf8UKZgQ0HyuxL/VnacadJ+D2Kox2TCEBuNQg5+w=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"www.xiaosige.com","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.26.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":false,"codeblock":{"theme":{"light":"atom-one-dark-reasonable","dark":"atom-one-dark-reasonable"},"prism":{"light":"prism-tomorrow","dark":"prism-tomorrow"},"copy_button":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"language":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"changyan","storage":true,"lazyload":true,"nav":null,"activeClass":"changyan"},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":true,"trigger":"auto"}}</script><script src="/js/config.js" defer></script>

    <meta name="description" content="介绍  Nginx是一个高性能的Web和反向代理服务器,它具有有很多非常优越的特性:  作为Web服务器: 相比Apache，Nginx 使用更少的资源，支持更多 的并发连接，体现更高的效率，这点使Nginx尤其受到虚拟主机提供商的欢迎。能够支持高达50,000个并发连接数的响应，感谢Nginx为我们选择了epoll and kqueue作为开发模型.">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux安装Nginx--两种方式">
<meta property="og:url" content="https://www.xiaosige.com/post/69813a0e.html">
<meta property="og:site_name" content="小四儿">
<meta property="og:description" content="介绍  Nginx是一个高性能的Web和反向代理服务器,它具有有很多非常优越的特性:  作为Web服务器: 相比Apache，Nginx 使用更少的资源，支持更多 的并发连接，体现更高的效率，这点使Nginx尤其受到虚拟主机提供商的欢迎。能够支持高达50,000个并发连接数的响应，感谢Nginx为我们选择了epoll and kqueue作为开发模型.">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www.xiaosige.com/post/69813a0e/nginx-001.png">
<meta property="og:image" content="https://www.xiaosige.com/post/69813a0e/nginx-002.png">
<meta property="article:published_time" content="2020-09-15T20:26:11.000Z">
<meta property="article:modified_time" content="2020-10-04T10:02:29.121Z">
<meta property="article:author" content="leeze">
<meta property="article:tag" content="Nginx">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www.xiaosige.com/post/69813a0e/nginx-001.png">


<link rel="canonical" href="https://www.xiaosige.com/post/69813a0e.html">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://www.xiaosige.com/post/69813a0e.html","path":"post/69813a0e.html","title":"Linux安装Nginx--两种方式"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Linux安装Nginx--两种方式 | 小四儿</title>
  

  <script src="/js/third-party/analytics/baidu-analytics.js" defer></script>
  <script async src="https://hm.baidu.com/hm.js?7a645cfcecaf8f711cd7518386adcc74"></script>







  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
  <script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous" defer></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.31/dist/fancybox/fancybox.umd.js" integrity="sha256-a+H7FYzJv6oU2hfsfDGM2Ohw/cR9v+hPfxHCLdmCrE8=" crossorigin="anonymous" defer></script>
  <script src="https://cdn.jsdelivr.net/npm/lozad@1.16.0/dist/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script><script src="/js/pjax.js" defer></script>

  <script src="https://cdn.jsdelivr.net/npm/hexo-generator-searchdb@1.5.0/dist/search.js" integrity="sha256-xFC6PJ82SL9b3WkGjFavNiA9gm5z6UBxWPiu4CYjptg=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdn.jsdelivr.net/npm/pdfobject@2.3.1/pdfobject.min.js","integrity":"sha256-jI72I8ZLVflVOisZIOaLvRew3tyvzeu6aZXFm7P7dEo="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js" defer></script>



  <script src="/js/third-party/fancybox.js" defer></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  <script src="https://cdn.jsdelivr.net/npm/quicklink@3.0.1/dist/quicklink.umd.js" integrity="sha256-44BednzIpUeQJcY8qtLyarFu0UCCTbgmWOvaoehiFQQ=" crossorigin="anonymous" defer></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":true,"archive":true,"delay":true,"timeout":3000,"priority":true,"ignores":null,"url":"https://www.xiaosige.com/post/69813a0e.html"}</script>
  <script src="/js/third-party/quicklink.js" defer></script>
<!-- https://www.layuicdn.com/layui/css/layui.css -->
<script src="https://www.layuicdn.com/layui/layui.js"></script>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>


<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.4/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/splitting@1.0.6/dist/splitting.min.js"></script>
<style type="text/css">
    .char{
      font-variation-settings: 'wght' var(--weight, 100);
      color: hsl(var(--hue), calc(var(--saturation) * 1%), 65%);
    }
</style>



<link rel="stylesheet" type="text/css" href="/css/shake.css" />


<link rel="stylesheet" type="text/css" href="/css/hover.css" />


<link rel="stylesheet" type="text/css" href="/zone/css/i_hover.css" />
<link rel="stylesheet" type="text/css" href="/css/injector/main.css" /><link rel="preload" as="style" href="/css/injector/light.css" /><link rel="preload" as="style" href="/css/injector/dark.css" />
  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>

<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="小四儿" type="application/atom+xml">
<link rel="alternate" href="/rss2.xml" title="小四儿" type="application/rss+xml"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">小四儿</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">心之所愿，无所不至！</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">61</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">25</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">149</span></a></li><li class="menu-item menu-item-welfare"><a href="/welfare" rel="section"><i class="fa fa-star fa-fw"></i>收藏</a></li><li class="menu-item menu-item-music"><a href="/music" rel="section"><i class="fa fa-music fa-fw"></i>音乐</a></li><li class="menu-item menu-item-photos"><a href="/photos" rel="section"><i class="fa fa-camera-retro fa-fw"></i>相册</a></li><li class="menu-item menu-item-links"><a href="/links" rel="section"><i class="fa fa-link fa-fw"></i>友链</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%8B%E7%BB%8D"><span class="nav-number">1.</span> <span class="nav-text">介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#yum%E5%AE%89%E8%A3%85"><span class="nav-number">2.</span> <span class="nav-text">yum安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#yum%E4%BB%93%E5%BA%93%E9%85%8D%E7%BD%AE"><span class="nav-number">2.1.</span> <span class="nav-text">yum仓库配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AE%89%E8%A3%85nginx"><span class="nav-number">2.2.</span> <span class="nav-text">安装nginx</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%A6%81%E6%AD%A2%E6%9B%B4%E6%96%B0"><span class="nav-number">2.3.</span> <span class="nav-text">禁止更新</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%9B%B4%E6%96%B0Nginx"><span class="nav-number">2.4.</span> <span class="nav-text">更新Nginx</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%91%BD%E4%BB%A4%E7%AE%A1%E7%90%86"><span class="nav-number">2.5.</span> <span class="nav-text">命令管理</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%BA%90%E4%BB%A3%E7%A0%81%E5%AE%89%E8%A3%85"><span class="nav-number">3.</span> <span class="nav-text">源代码安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%BA%90%E7%A0%81%E4%B8%8B%E8%BD%BD"><span class="nav-number">3.1.</span> <span class="nav-text">源码下载</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%96%B0%E5%A2%9E%E7%94%A8%E6%88%B7"><span class="nav-number">3.2.</span> <span class="nav-text">新增用户</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E4%BE%9D%E8%B5%96%E7%8E%AF%E5%A2%83"><span class="nav-number">3.3.</span> <span class="nav-text">安装依赖环境</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BF%9B%E8%A1%8C%E9%85%8D%E7%BD%AE"><span class="nav-number">3.4.</span> <span class="nav-text">进行配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85nginx"><span class="nav-number">3.5.</span> <span class="nav-text">编译安装nginx</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E5%90%AF%E5%8A%A8"><span class="nav-number">4.</span> <span class="nav-text">设置开机启动</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="leeze"
      src="https://static.xiaosige.com/img/avatar/avatar.jpg">
  <p class="site-author-name" itemprop="name">leeze</p>
  <div class="site-description" itemprop="description">因上努力，果上随缘！</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">149</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">61</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/leeze2012" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;leeze2012" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.teambition.com/" title="Teambition → https:&#x2F;&#x2F;www.teambition.com" rel="noopener me" target="_blank"><i class="fab fa-mixcloud fa-fw"></i>Teambition</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/leeze" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;leeze" rel="noopener me" target="_blank"><i class="fab fa-gg fa-fw"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.jianshu.com/u/e4c5daf92fa6" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;e4c5daf92fa6" rel="noopener me" target="_blank"><i class="fab fa-telegram fa-fw"></i>简书</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://codeup.aliyun.com/" title="Codeup → https:&#x2F;&#x2F;codeup.aliyun.com" rel="noopener me" target="_blank"><i class="fab fa-envira fa-fw"></i>Codeup</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://blog.csdn.net/lileeze" title="CSDN → https:&#x2F;&#x2F;blog.csdn.net&#x2F;lileeze" rel="noopener me" target="_blank"><i class="fa fa-crosshairs fa-fw"></i>CSDN</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://dev.tencent.com/u/leeze" title="腾讯云 → https:&#x2F;&#x2F;dev.tencent.com&#x2F;u&#x2F;leeze" rel="noopener me" target="_blank"><i class="fab fa-jsfiddle fa-fw"></i>腾讯云</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.upyun.com/" title="又拍云 → https:&#x2F;&#x2F;www.upyun.com" rel="noopener me" target="_blank"><i class="fab fa-jsfiddle fa-fw"></i>又拍云</a>
      </span>
  </div>

<div class="site-overview-item animated" style="height:140px;">
    <div class="wrap">
        <div class="cup">
            <div class="cup__mouse"></div>
            <div class="cup__eyes"></div>
            <div class="cup__label">多喝水</div>
        </div>
        <div class="cup-shadow"></div>
    </div>
</div>

<style>

.wrap {
  width: 210px;
  height: 90px;
  -webkit-transform: translate(-50%, 50%);
          transform: translate(-50%, 50%);
  position: relative;
  left: 40%;
  /*top: 20%;*/
}

.cup {
  width: 140px;
  height: 100px;
  background: #FFF;
  box-shadow: inset 0px -10px 0 0 #EDDFE6;
  border-radius: 5px 5px 50px 50px;
  -webkit-transform-origin: bottom center;
          transform-origin: bottom center;
  -webkit-animation: .6s linear 0s infinite alternate cup;
          animation: .6s linear 0s infinite alternate cup;
  border: 3px solid #000;
  position: absolute;
  bottom: 0;
  left: 40px;
  z-index: 2;
}
.cup::before {
  content: '';
  width: 140px;
  background: #91ECED;
  height: 40px;
  border-radius: 100%;
  border: 3px solid #000;
  box-shadow: inset 0 20px 0 0 #fff;
  -webkit-animation: .6s linear 0s infinite alternate water;
          animation: .6s linear 0s infinite alternate water;
  position: absolute;
  top: -20px;
  left: -3px;
}
.cup::after {
  content: '';
  width: 22px;
  height: 26px;
  background: transparent;
  border-radius: 30% 100% 100% 30%;
  border: 3px solid #000;
  border-left: none;
  box-shadow: 4px 0 0 9px #fff, 6px 0 0 10px #000;
  position: absolute;
  bottom: 35px;
  right: -20px;
}
.cup__mouse {
  top: 45px;
  left: 45px;
  position: absolute;
  height: 30px;
  width: 50px;
  border: 3px solid #000;
  border-radius: 50%;
  -webkit-clip-path: polygon(50% 10%, 91% 100%, 5% 100%);
          clip-path: polygon(50% 10%, 91% 100%, 5% 100%);
}
.cup__eyes {
  width: 15px;
  height: 15px;
  background: #000;
  border-radius: 50%;
  box-shadow: 58px 0 0 0 #000;
  position: absolute;
  top: 55px;
  left: 35px;
}
.cup__label {
  width: 48px;
  height: 35px;
  box-sizing: content-box;
  /*padding-top: 10px;*/
  background: #ff7600;
  border: 2px solid #000;
  border-bottom: none;
  -webkit-transform-origin: top center;
          transform-origin: top center;
  -webkit-animation: .6s linear 0s infinite alternate label;
          animation: .6s linear 0s infinite alternate label;
  position: absolute;
  top: 40px;
  left: 45px;
  color: #fff
}
.cup__label::before {
  content: '';
  width: 3px;
  height: 15px;
  background: #000;
  -webkit-animation: .6s linear 0s infinite alternate label-line;
          animation: .6s linear 0s infinite alternate label-line;
  position: absolute;
  left: 25px;
  top: -16px;
}
.cup__label::after {
  content: '';
  position: absolute;
  left: -1px;
  bottom: 0;
  width: 0;
  height: 0;
  -webkit-filter: drop-shadow(0 -2px 0 black);
          filter: drop-shadow(0 -2px 0 black);
  border-bottom: 7px solid #fff;
  border-left: 26px solid transparent;
  border-right: 26px solid transparent;
}

.cup-shadow {
  width: 135px;
  height: 90px;
  background: #7CE589;
  border-radius: 40% 40% 100% 100%;
  -webkit-transform-origin: bottom center;
          transform-origin: bottom center;
  -webkit-animation: .6s linear 0s infinite alternate shadow;
          animation: .6s linear 0s infinite alternate shadow;
  position: absolute;
  bottom: -16px;
  left: 55px;
  z-index: 1;
}
.cup-shadow::after {
  content: '';
  width: 20px;
  height: 25px;
  background: transparent;
  border-radius: 30% 100% 100% 30%;
  border-left: none;
  box-shadow: 5px 0 0 5px #7CE589;
  position: absolute;
  bottom: 35px;
  right: -10px;
}

@-webkit-keyframes cup {
  0% {
    -webkit-transform: rotate(10deg);
            transform: rotate(10deg);
    box-shadow: inset -10px -10px 0 0 #EDDFE6;
  }
  100% {
    -webkit-transform: rotate(-10deg);
            transform: rotate(-10deg);
    box-shadow: inset 10px -10px 0 0 #EDDFE6;
  }
}

@keyframes cup {
  0% {
    -webkit-transform: rotate(10deg);
            transform: rotate(10deg);
    box-shadow: inset -10px -10px 0 0 #EDDFE6;
  }
  100% {
    -webkit-transform: rotate(-10deg);
            transform: rotate(-10deg);
    box-shadow: inset 10px -10px 0 0 #EDDFE6;
  }
}
@-webkit-keyframes water {
  0% {
    box-shadow: inset 30px 20px 0 0 #fff;
  }
  100% {
    box-shadow: inset -30px 20px 0 0 #fff;
  }
}
@keyframes water {
  0% {
    box-shadow: inset 30px 20px 0 0 #fff;
  }
  100% {
    box-shadow: inset -30px 20px 0 0 #fff;
  }
}
@-webkit-keyframes label {
  0% {
    -webkit-transform: rotate(40deg);
            transform: rotate(40deg);
  }
  100% {
    -webkit-transform: rotate(-40deg);
            transform: rotate(-40deg);
  }
}
@keyframes label {
  0% {
    -webkit-transform: rotate(40deg);
            transform: rotate(40deg);
  }
  100% {
    -webkit-transform: rotate(-40deg);
            transform: rotate(-40deg);
  }
}
@-webkit-keyframes label-line {
  0% {
    height: 15px;
    top: -16px;
  }
  25% {
    height: 22px;
    top: -22px;
  }
  50% {
    height: 15px;
    top: -16px;
  }
  100% {
    height: 22px;
    top: -22px;
  }
}
@keyframes label-line {
  0% {
    height: 15px;
    top: -16px;
  }
  25% {
    height: 22px;
    top: -22px;
  }
  50% {
    height: 15px;
    top: -16px;
  }
  100% {
    height: 22px;
    top: -22px;
  }
}
@-webkit-keyframes shadow {
  0% {
    -webkit-transform: skewX(-10deg);
            transform: skewX(-10deg);
  }
  100% {
    -webkit-transform: skewX(20deg);
            transform: skewX(20deg);
  }
}
@keyframes shadow {
  0% {
    -webkit-transform: skewX(-10deg);
            transform: skewX(-10deg);
  }
  100% {
    -webkit-transform: skewX(20deg);
            transform: skewX(20deg);
  }
}

.sidebar-panel{
    min-height: calc(var(--sidebar-wrapper-height) * 0.75);
}
.sidebar-toc-active .post-toc-wrap,
.sidebar-overview-active .site-overview-wrap {
  display: block;
}
</style>




<script src="/zone/js/canvasTime.js" async></script>
<div style="display:none;">
  <canvas id="canvas" style="width:60%;">当前浏览器不支持canvas，请更换浏览器后再试</canvas>
</div>
<style>
// 粒子时钟样式
.site-overview {
  text-align: center;
}

canvas#canvas {
  margin-top: 70px;
}
</style>


<div class="site-overview-item animated">
    <div style="">
        <iframe id="sjFrame" loading="lazy" src="/zone/tool/sj/index.html" border="0" width="100%" height="100" frameborder="no"> </iframe>
    </div>
</div>

        </div>
      </div>
    </div>

    
        <div class="pjax">
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://www.xiaosige.com/post/69813a0e.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://static.xiaosige.com/img/avatar/avatar.jpg">
      <meta itemprop="name" content="leeze">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小四儿">
      <meta itemprop="description" content="因上努力，果上随缘！">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Linux安装Nginx--两种方式 | 小四儿">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Linux安装Nginx--两种方式
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-09-16 04:26:11" itemprop="dateCreated datePublished" datetime="2020-09-16T04:26:11+08:00">2020-09-16</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2020-10-04 18:02:29" itemprop="dateModified" datetime="2020-10-04T18:02:29+08:00">2020-10-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Nginx/" itemprop="url" rel="index"><span itemprop="name">Nginx</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>



    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>15k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>14 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h3 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h3><p>  Nginx是一个高性能的Web和反向代理服务器,它具有有很多非常优越的特性:<br>  <b>作为Web服务器</b>: 相比Apache，Nginx 使用更少的资源，支持更多 的并发连接，体现更高的效率，这点使Nginx尤其受到虚拟主机提供商的欢迎。能够支持高达50,000个并发连接数的响应，感谢Nginx为我们选择了epoll and kqueue作为开发模型.</p>
<span id="more"></span>
<p>  <b>作为负载均衡服务器</b>: Nginx 既可以在内部直接支持Rails和PHP，也可以支持作为HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。<br>  <b>作为邮件代理服务器</b>: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器)，Last.fm 描述了成功并且美妙的使用经验。<br>  <b>Nginx安装非常的简单，配置文件非常简洁(还能够支持perl语法)，Bugs非常少的服务器</b>: Nginx启动特别容易，并且几乎可以做到7*24不间断运行，即使运行数个月也不需要重新启动。你还能够在不间断服务的情况下进行软件版本的升级。</p>
<h3 id="yum安装"><a href="#yum安装" class="headerlink" title="yum安装"></a>yum安装</h3><h4 id="yum仓库配置"><a href="#yum仓库配置" class="headerlink" title="yum仓库配置"></a>yum仓库配置</h4><p>  在<code>/etc/yum.repos.d/</code>下新建一个nginx.repo，加入<a target="_blank" rel="noopener" href="http://nginx.org/en/linux_packages.html">nginx官方提供的源</a> , <a target="_blank" rel="noopener" href="https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/">Installing NGINX Open Source</a></p>
<pre class="line-numbers language-nginx" data-language="nginx"><code class="language-nginx">[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/&lt;OS&gt;/&lt;OSRELEASE&gt;/$basearch/
gpgcheck=0
enabled=1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>  注意其中的<code>&lt;OS&gt;</code> 为系统名，<code>&lt;OSRELEASE&gt;</code>为系统大版本</p>
<ol>
<li>CentOS7<br><code>vi /etc/yum.repos.d/nginx.repo</code><pre class="line-numbers language-nginx" data-language="nginx"><code class="language-nginx">[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li>
<li>CentOS6<br><code>vi /etc/yum.repos.d/nginx.repo</code><pre class="line-numbers language-nginx" data-language="nginx"><code class="language-nginx">[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li>
</ol>
<h4 id="安装nginx"><a href="#安装nginx" class="headerlink" title="安装nginx"></a>安装nginx</h4><ol>
<li>直接安装会安装当前的最新版本<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> <span class="token parameter variable">-y</span> nginx<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li>
<li>该源仓库下有多个版本的nginx可供安装，可以用如下命令查看<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token parameter variable">--showduplicates</span> list nginx<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li>
<li>选择其中一个版本安装<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> <span class="token parameter variable">-y</span> nginx-版本号
<span class="token comment"># 如下</span>
yum <span class="token function">install</span> <span class="token parameter variable">-y</span> <span class="token number">1.18</span>.0-1.el6.ngx<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li>
</ol>
<h4 id="禁止更新"><a href="#禁止更新" class="headerlink" title="禁止更新"></a>禁止更新</h4><p>  我们在安装之后，为了能够正常运行，我们一般会禁止Nginx进行更新。因为在yum更新了Nginx之后，Nginx会自动重启。这对于我们来说是没有必要的，所以我们可以屏蔽更新。我们可以这样，将下列指定放到你的<code>/etc/yum.conf</code>文件中：</p>
<pre class="line-numbers language-properties" data-language="properties"><code class="language-properties"><span class="token key attr-name">exclude</span><span class="token punctuation">=</span><span class="token value attr-value">nginx</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<h4 id="更新Nginx"><a href="#更新Nginx" class="headerlink" title="更新Nginx"></a>更新Nginx</h4><p>  一般在生产环境，我们都是禁用更新的。所以说，这里只是作为一个参考<br>  我们需要执行的命令就是：</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum update nginx<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>  <code> 注意： 在使用 yum 更新之后，Nginx会自动重启。</code></p>
<h4 id="命令管理"><a href="#命令管理" class="headerlink" title="命令管理"></a>命令管理</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">systemctl start nginx   <span class="token comment"># 启动</span>
systemctl restart nginx <span class="token comment"># 重启</span>
nginx <span class="token parameter variable">-t</span>                <span class="token comment"># 测试配置文件语法是否正确</span>
systemctl reload nginx  <span class="token comment"># 重载配置文件</span>
systemctl stop nginx    <span class="token comment"># 停止</span>
systemctl <span class="token builtin class-name">enable</span> nginx  <span class="token comment"># 启动开机启动</span>
systemctl diasble nginx <span class="token comment"># 禁止开机启动</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h3 id="源代码安装"><a href="#源代码安装" class="headerlink" title="源代码安装"></a>源代码安装</h3><p>  如果已安装，则remove掉<code>yum remove nginx</code></p>
<h4 id="源码下载"><a href="#源码下载" class="headerlink" title="源码下载"></a>源码下载</h4><p>  安装wget并下载nginx源码包， 去 <a target="_blank" rel="noopener" href="http://nginx.org/download/">http://nginx.org/download/</a> 可以找到历史版本的包</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> <span class="token parameter variable">-y</span> <span class="token function">wget</span> <span class="token operator">&amp;&amp;</span> <span class="token function">wget</span> http://nginx.org/download/nginx-1.19.2.tar.gz

<span class="token function">tar</span> <span class="token parameter variable">-zxvf</span> nginx-1.19.2.tar.gz<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<h4 id="新增用户"><a href="#新增用户" class="headerlink" title="新增用户"></a>新增用户</h4><pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token function">groupadd</span> www
<span class="token function">useradd</span> <span class="token parameter variable">-g</span> www www<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<blockquote>
<p> useradd -g www -s /sbin/nologin -M www</p>
</blockquote>
<h4 id="安装依赖环境"><a href="#安装依赖环境" class="headerlink" title="安装依赖环境"></a>安装依赖环境</h4><ol>
<li>安装gcc<br>安装 nginx 需要先将官网下载的源码进行编译，编译依赖 gcc 环境。安装指令如下：<br>安装gcc<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token parameter variable">-y</span> <span class="token function">install</span> gcc automake autoconf libtool <span class="token function">make</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
安装g++<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> gcc gcc-c++<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li>
<li>安装PCRE pcre-devel<br>Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法。这里需要安装两个安装包pcre和pcre-devel。第一个安装包提供编译版本的库，而第二个提供开发阶段的头文件和编译项目的源代码。安装指令如下：<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> <span class="token parameter variable">-y</span> pcre pcre-devel<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li>
<li>安装zlib<br>zlib库提供了开发人员的压缩算法，在Nginx的各种模块中需要使用gzip压缩。安装指令如下:<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> <span class="token parameter variable">-y</span> zlib zlib-devel<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></li>
<li>安装Open SSL<br>nginx不仅支持 http协议，还支持 https（即在 ssl 协议上传输 http），如果使用了 https，需要安装 OpenSSL 库。安装指令如下：<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash">yum <span class="token function">install</span> <span class="token parameter variable">-y</span> openssl openssl-devel<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
环境结束.</li>
</ol>
<h4 id="进行配置"><a href="#进行配置" class="headerlink" title="进行配置"></a>进行配置</h4><p>没有特别配置，直接<code>./configure</code>就好了。安装完成后可以通过<code>nginx -V</code>查看选择的模块。</p>
<p>部分编译参数说明</p>
<table>
<tbody><tr>
<th>参数</th>
<th>描述</th>
</tr>
<tr>
<td>--prefix</td>
<td>定义nginx安装路径</td>
</tr>
<tr>
<td>--sbin-path</td>
<td>定义nginx可执行文件路径</td>
</tr>
<tr>
<td>--modules-path</td>
<td>nginx模块路径</td>
</tr>
<tr>
<td>--conf-path</td>
<td>nginx配置文件路径</td>
</tr>
<tr>
<td>--error-log-path、--http-log-path</td>
<td>错误和访问日志路径</td>
</tr>
<tr>
<td>--with-openssl</td>
<td>定义编译使用的openssl，默认为系统自带openssl</td>
</tr>
<tr>
<td>--with-http_ssl_module</td>
<td>ssl模块</td>
</tr>
</tbody></table>

<br>

<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># ./configure --prefix=/usr/local/nginx \</span>
--sbin-path<span class="token operator">=</span>/usr/sbin/nginx <span class="token punctuation">\</span>
--modules-path<span class="token operator">=</span>/usr/lib64/nginx/modules <span class="token punctuation">\</span>
--conf-path<span class="token operator">=</span>/usr/local/nginx/nginx.conf <span class="token punctuation">\</span>
--error-log-path<span class="token operator">=</span>/usr/local/nginx/error.log <span class="token punctuation">\</span>
--http-log-path<span class="token operator">=</span>/usr/local/nginx/access.log <span class="token punctuation">\</span>
--pid-path<span class="token operator">=</span>/usr/local/nginx/nginx.pid <span class="token punctuation">\</span>
--lock-path<span class="token operator">=</span>/usr/local/nginx/nginx.lock <span class="token punctuation">\</span>
--http-client-body-temp-path<span class="token operator">=</span>/usr/local/nginx/client_temp <span class="token punctuation">\</span>
--http-proxy-temp-path<span class="token operator">=</span>/usr/local/nginx/proxy_temp <span class="token punctuation">\</span>
--http-fastcgi-temp-path<span class="token operator">=</span>/usr/local/nginx/fastcgi_temp <span class="token punctuation">\</span>
--http-uwsgi-temp-path<span class="token operator">=</span>/usr/local/nginx/uwsgi_temp <span class="token punctuation">\</span>
--http-scgi-temp-path<span class="token operator">=</span>/usr/local/nginx/scgi_temp <span class="token punctuation">\</span>
<span class="token parameter variable">--user</span><span class="token operator">=</span>www <span class="token punctuation">\</span>
<span class="token parameter variable">--group</span><span class="token operator">=</span>www <span class="token punctuation">\</span>
--with-compat <span class="token punctuation">\</span>
--with-file-aio <span class="token punctuation">\</span>
--with-threads <span class="token punctuation">\</span>
--with-http_addition_module <span class="token punctuation">\</span>
--with-http_auth_request_module <span class="token punctuation">\</span>
--with-http_dav_module <span class="token punctuation">\</span>
--with-http_flv_module <span class="token punctuation">\</span>
--with-http_gunzip_module <span class="token punctuation">\</span>
--with-http_gzip_static_module <span class="token punctuation">\</span>
--with-http_mp4_module <span class="token punctuation">\</span>
--with-http_random_index_module <span class="token punctuation">\</span>
--with-http_realip_module <span class="token punctuation">\</span>
--with-http_secure_link_module <span class="token punctuation">\</span>
--with-http_slice_module <span class="token punctuation">\</span>
--with-http_ssl_module <span class="token punctuation">\</span>
--with-http_stub_status_module <span class="token punctuation">\</span>
--with-http_sub_module <span class="token punctuation">\</span>
--with-http_v2_module <span class="token punctuation">\</span>
--with-mail <span class="token punctuation">\</span>
--with-mail_ssl_module <span class="token punctuation">\</span>
--with-stream <span class="token punctuation">\</span>
--with-stream_realip_module <span class="token punctuation">\</span>
--with-stream_ssl_module <span class="token punctuation">\</span>
--with-stream_ssl_preread_module<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<br>

<img data-src="/post/69813a0e/nginx-001.png" class="" title="nginx编译输出">

<p>上面的编译是使用了系统默认的openssl，如果想使用更高版本的openssl进行编译的话。可以加上<code>--with-openssl=openssl安装路径</code>来自定义。高版本的openssl安装可以参考 <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/bf5a55a0a814">这篇文章</a>。</p>
<p><code>--with-openssl</code> 参数虽然可以指定 OpenSSL 路径，但只支持 OpenSSL 的源代码，不支持已编译好的 OpenSSL。每回更新 nginx 都要重新编译 OpenSSL 很麻烦 。以下是解决方案<br>打开nginx源码解压目录下的<code>auto/lib/openssl/conf</code>,找到所有带<code>.openssl</code>的行</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token assign-left variable">CORE_INCS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_INCS</span> <span class="token variable">$OPENSSL</span>/.openssl/include"</span>
<span class="token assign-left variable">CORE_DEPS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_DEPS</span> <span class="token variable">$OPENSSL</span>/.openssl/include/openssl/ssl.h"</span>
<span class="token assign-left variable">CORE_LIBS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_LIBS</span> <span class="token variable">$OPENSSL</span>/.openssl/lib/libssl.a"</span>
<span class="token assign-left variable">CORE_LIBS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_LIBS</span> <span class="token variable">$OPENSSL</span>/.openssl/lib/libcrypto.a"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>
<p>改成下面的样子，去掉<code>.openssl/</code></p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token assign-left variable">CORE_INCS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_INCS</span> <span class="token variable">$OPENSSL</span>/include"</span>
<span class="token assign-left variable">CORE_DEPS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_DEPS</span> <span class="token variable">$OPENSSL</span>/include/openssl/ssl.h"</span>
<span class="token assign-left variable">CORE_LIBS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_LIBS</span> <span class="token variable">$OPENSSL</span>/lib/libssl.a"</span>
<span class="token assign-left variable">CORE_LIBS</span><span class="token operator">=</span><span class="token string">"<span class="token variable">$CORE_LIBS</span> <span class="token variable">$OPENSSL</span>/lib/libcrypto.a"</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre>
<p>进行编译</p>
<pre class="line-numbers language-bash" data-language="bash"><code class="language-bash"><span class="token punctuation">[</span>root@localhost ~<span class="token punctuation">]</span><span class="token comment"># ./configure --prefix=/usr/local/nginx \</span>
--sbin-path<span class="token operator">=</span>/usr/sbin/nginx <span class="token punctuation">\</span>
--modules-path<span class="token operator">=</span>/usr/lib64/nginx/modules <span class="token punctuation">\</span>
--conf-path<span class="token operator">=</span>/usr/local/nginx/nginx.conf <span class="token punctuation">\</span>
--error-log-path<span class="token operator">=</span>/usr/local/nginx/error.log <span class="token punctuation">\</span>
--http-log-path<span class="token operator">=</span>/usr/local/nginx/access.log <span class="token punctuation">\</span>
--pid-path<span class="token operator">=</span>/usr/local/nginx/nginx.pid <span class="token punctuation">\</span>
--lock-path<span class="token operator">=</span>/usr/local/nginx/nginx.lock <span class="token punctuation">\</span>
--http-client-body-temp-path<span class="token operator">=</span>/usr/local/nginx/client_temp <span class="token punctuation">\</span>
--http-proxy-temp-path<span class="token operator">=</span>/usr/local/nginx/proxy_temp <span class="token punctuation">\</span>
--http-fastcgi-temp-path<span class="token operator">=</span>/usr/local/nginx/fastcgi_temp <span class="token punctuation">\</span>
--http-uwsgi-temp-path<span class="token operator">=</span>/usr/local/nginx/uwsgi_temp <span class="token punctuation">\</span>
--http-scgi-temp-path<span class="token operator">=</span>/usr/local/nginx/scgi_temp <span class="token punctuation">\</span>
<span class="token parameter variable">--user</span><span class="token operator">=</span>www <span class="token punctuation">\</span>
<span class="token parameter variable">--group</span><span class="token operator">=</span>www <span class="token punctuation">\</span>
--with-compat <span class="token punctuation">\</span>
--with-file-aio <span class="token punctuation">\</span>
--with-threads <span class="token punctuation">\</span>
--with-http_addition_module <span class="token punctuation">\</span>
--with-http_auth_request_module <span class="token punctuation">\</span>
--with-http_dav_module <span class="token punctuation">\</span>
--with-http_flv_module <span class="token punctuation">\</span>
--with-http_gunzip_module <span class="token punctuation">\</span>
--with-http_gzip_static_module <span class="token punctuation">\</span>
--with-http_mp4_module <span class="token punctuation">\</span>
--with-http_random_index_module <span class="token punctuation">\</span>
--with-http_realip_module <span class="token punctuation">\</span>
--with-http_secure_link_module <span class="token punctuation">\</span>
--with-http_slice_module <span class="token punctuation">\</span>
--with-http_ssl_module <span class="token punctuation">\</span>
--with-http_stub_status_module <span class="token punctuation">\</span>
--with-http_sub_module <span class="token punctuation">\</span>
--with-http_v2_module <span class="token punctuation">\</span>
--with-mail <span class="token punctuation">\</span>
--with-mail_ssl_module <span class="token punctuation">\</span>
--with-stream <span class="token punctuation">\</span>
--with-stream_realip_module <span class="token punctuation">\</span>
--with-stream_ssl_module <span class="token punctuation">\</span>
--with-openssl<span class="token operator">=</span>/usr/local/openssl <span class="token punctuation">\</span>
--with-stream_ssl_preread_module<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<br>

<img data-src="/post/69813a0e/nginx-002.png" class="" title="nginx编译输出">


<p>部分编译参数说明</p>
<table>
<tbody><tr>
<th>参数选项</th>
<th>基本解释</th>
</tr>
<tr>
<td>–help</td>
<td>打印帮助信息</td>
</tr>
<tr>
<td>–prefix=PATH</td>
<td>Nginx安装部署后的根目录 默认为/usr/local/nginx目录。注意：这个目标的设置会影响其他参数中的相对目录。例如，如果设置了–sbin-path=sbin/nginx，那么实际上可执行文件会被放到/usr/local/nginx/sbin/nginx中</td>
</tr>
<tr>
<td>–sbin-path=PATH</td>
<td>可执行文件的放置路径 &lt;prefix&gt;/sbin/nginx </td>
</tr>
<tr>
<td>–conf-path=PATH</td>
<td>配置文件的放置路径 &lt;prefix&gt;/conf/nginx.conf</td>
</tr>
<tr>
<td>–error-log-path=PATH</td>
<td>error日志文件的放置路径。error日志用于定位问题，可输出多种级别（包括debug调试级别）的日志。它的配置非常灵活，可以在nginx.conf里配置为不同请求的日志并输出到不同的log文件中。这里是默认的Nginx核心日志路径 &lt;prefix&gt;/logs/error.log</td>
</tr>
<tr>
<td>–pid-path=PATH</td>
<td>pid文件的存放路径。这个文件里仅以ASC II码存放着Nginx master的进程ID，有了这个进程ID，在使用命令行（例如nginx -s reload）通过读取master进程ID向master进程发送信号时，才能对运行中的Nginx服务产生作用 &lt;prefix&gt;/logs/nginx.pid</td>
</tr>
<tr>
<td>–lock-path=PATH</td>
<td>lock文件的放置路径 &lt;prefix&gt;/logs/nginx.lock</td>
</tr>
<tr>
<td>–user=USER</td>
<td>指定Nginx worker进程运行时所属的用户。注意：不要将启动worker进程的用户设为root，在worker进程出问题时master进程要具备停止/启动worker进程的能力</td>
</tr>
<tr>
<td>–group=GROUP</td>
<td>指定Nginx worker进程运行时所属的组</td>
</tr>
<tr>
<td>–build=NAME</td>
<td>configure执行时与编译期间产生的临时文件名称</td>
</tr>
<tr>
<td>–builddir=DIR</td>
<td>configure执行时与编译期间产生的临时文件放置的目录，包括产生的Makefile、C源文件、目标文件、可执行文件等 &lt;nginx source path&gt;/objs</td>
</tr>
<tr>
<td>–with-rtsig_module</td>
<td>使用rtsig module处理事件驱动 默认情况下，Nginx是不安装rtsig module的，即不会把rtsig module编译进最终的Nginx二进制程序中</td>
</tr>
<tr>
<td>–with-select_module</td>
<td>使用select module处理事件驱动 select是Linux提供的一种多路复用机制，在epoll调用没有诞生前，例如在Linux 2.4及其之前的内核中，select用于支持服务器提供高并发连接 默认情况下，Nginx是不安装select module的，但如果没有找到其他更好的事件模块，该模块将会被安装</td>
</tr>
<tr>
<td>–without-select_module</td>
<td>不安装select module</td>
</tr>
<tr>
<td>–with-poll_module</td>
<td>使用poll module处理事件驱动 poll的性能与select类似，在大量并发连接下性能都远不如epoll。默认情况下，Nginx是不安装poll</td>
</tr>
<tr>
<td>–without-poll_module</td>
<td>不安装poll module</td>
</tr>
<tr>
<td>–with-file-aio</td>
<td>使用AIO方式处理事件驱动 (IO异步大幅度提升性能，需要内核 2.6.22 以上的版本)</td>
</tr>
<tr>
<td>–with-ipv6</td>
<td>使Nginx支持IPv6</td>
</tr>
<tr>
<td>–with-https_ssl_module</td>
<td>安装https ssl module。该模块使Nginx支持SSL协议，提供HTTPS服务。 注意：该模块的安装依赖于OpenSSL开源软件，即首先应确保已经在之前的参数中配置了OpenSSL需要安装 OpenSSL library yum install openssl-devel | # apt-get install libssl-dev</td>
</tr>
<tr>
<td>–with-https_spdy_module</td>
<td>开启 ngx_https_spdy_module 模块。是Google开发的基于TCP的应用层协议，用以最小化网络延迟，提升网络速度，优化用户的网络使用体验。SPDY并不是一种用于替代HTTP的协议，而是对HTTP协议的增强</td>
</tr>
<tr>
<td>–with-https_realip_module</td>
<td>开启 ngx_https_realip_module 模块 。此模块支持显示真实来源IP地址，主要用于NGINX做前端负载均衡服务器使用。</td>
</tr>
<tr>
<td>–with-https_addition_module</td>
<td>开启 https addtion module。该模块可以在返回客户端的HTTP包体头部或者尾部增加内容。作为一个输出过滤器，支持不完全缓冲，分部分响应请求，游戏服务器不必安装，门户网站可以安装，有利于被搜索引擎收录页面信息。</td>
</tr>
<tr>
<td>–with-https_xslt_module</td>
<td>开启 ngx_https_xslt_module 模块 这个模块可以使XML格式的数据在发给客户端前加入XSL渲染，0.7.8后面版本才可以使用。</td>
</tr>
<tr>
<td>–with-https_image_filter_module</td>
<td>开启 ngx_https_image_filter_module 模块 。这个模块将符合配置的图片实时压缩为指定大小（width*height）的缩略图再发送给用户，目前支持JPEG、PNG、GIF格式。 注意：这个模块依赖于开源的libgd库，在安装前确保操作系统已经安装了libgd，是nginx提供的集成图片处理模块，支持nginx-0.7.54以后的版本，在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可，就可以用它实时缩放图片，旋转图片，验证图片有效性以及获取图片宽高以及图片类型信息，由于是即时计算的结果，所以网站访问量大的话，不建议使用。</td>
</tr>
<tr>
<td>–with-https_geoip_module</td>
<td>开启 ngx_https_geoip_module 模块，这个模块基于客户端的IP地址创建一些ngx_https_geoip_module变量，并与MaxMindGeoIP文件进行匹配，该模块仅用于0.7.63和0.8.6版本之后。 需要安装 yum install geoip-devel | apt-get install geoip-bin geoip-database libgeoip-dev</td>
</tr>
<tr>
<td>–with-https_sub_module</td>
<td>开启 ngx_https_sub_module 。该模块可以在Nginx返回客户端的HTTP响应包中将指定的字符串替换为自己需要的字符串 例如，在HTML的返回中，将替换为<script language="”javascript”" src="”$script”"></script></td>
</tr>
<tr>
<td>–with-https_dav_module</td>
<td>开启 ngx_https_dav_module 模块。这个模块可以让Nginx支持Webdav标准，如支持Webdav协议中的PUT、DELETE、COPY、MOVE、MKCOL等请求 默认情况下为关闭，需编译开启,如果开启WebDAV扩展动作模块，（可为文件和目录指定权限）</td>
</tr>
<tr>
<td>–with-https_flv_module</td>
<td>开启 ngx_https_flv_module 模块 ，这个模块可以在向客户端返回响应时，对FLV格式的视频文件在header头做一些处理，使得客户端可以观看、拖动FLV视频</td>
</tr>
<tr>
<td>–with-https_mp4_module</td>
<td>开启 ngx_https_mp4_module 模块，该模块使客户端可以观看、拖动MP4视频</td>
</tr>
<tr>
<td>–with-https_gunzip_module</td>
<td>开启 ngx_https_gunzip_module 模块，是一个过滤器， 它为不支持“gzip”编码方法的客户端解压具有“Content-Encoding: gzip”头的响应。 当希望存储压缩后的数据以节省空间和减少I/O开销，又不希望对那些不支持gzip压缩的客户端造成不利影响时， 此模块会派上用途</td>
</tr>
<tr>
<td>–with-https_gzip_static_module</td>
<td>开启 ngx_https_gzip_static_module 模块 ，允许发送以“.gz”作为文件扩展名的预压缩文件，防止文件被重复压缩，以替代发送普通文件。如果采用gzip模块把一些文档进行gzip格式压缩后再返回给客户端，那么对同一个文件每次都会重新压缩，这是比较消耗服务器CPU资源的。</td>
</tr>
<tr>
<td>–with-https_auth_request_module</td>
<td>开启 ngx_https_auth_request_module 模块</td>
</tr>
<tr>
<td>–with-https_random_index_module</td>
<td>开启 ngx_https_random_index_module 模块 ，该模块在客户端访问某个目录时，随机返回该目录下的索引文件</td>
</tr>
<tr>
<td>–with-https_secure_link_module</td>
<td>开启 ngx_https_secure_link_module ，该模块提供一种验证请求是否有效的机制。例如，它会验证URL中需要加入的token参数是否属于特定客户端发来的，以及检查时间戳是否过期（计算和检查要求所需的安全链接网址（防盗链））</td>
</tr>
<tr>
<td>–with-https_degradation_module</td>
<td>开启 ngx_https_degradation_module 模块，该模块针对一些特殊的系统调用（如sbrk）做一些优化，允许在内存不足的情况下返回204或444码。</td>
</tr>
<tr>
<td>–with-https_stub_status_module</td>
<td>开启 ngx_https_stub_status_module 模块，该模块可以让运行中的Nginx提供性能统计页面，获取相关的并发连接、请求的信息</td>
</tr>
<tr>
<td>–without-https_charset_module</td>
<td>关闭 https charset module。这个模块可以将服务器发出的HTTP响应重编码</td>
</tr>
<tr>
<td>–without-https_gzip_module</td>
<td>关闭 ngx_https_gzip_module模块，在服务器发出的HTTP响应包中，这个模块可以按照配置文件指定的content-type对特定大小的HTTP响应包体执行gzip压缩</td>
</tr>
<tr>
<td>–without-https_ssi_module</td>
<td>关闭 ngx_https_ssi_module模块，该模块可以在向用户返回的HTTP响应包体中加入特定的内容，如HTML文件中固定的页头和页尾</td>
</tr>
<tr>
<td>–without-https_userid_module</td>
<td>关闭 ngx_https_userid_module模块，这个模块可以通过HTTP请求头部信息里的一些字段认证用户信息，以确定请求是否合法</td>
</tr>
<tr>
<td>–without-https_access_module</td>
<td>关闭 访问模块，这个模块可以根据IP地址限制能够访问服务器的客户端</td>
</tr>
<tr>
<td>–without-https_auth_basic_module</td>
<td>禁用基本的认证模块，这个模块可以提供最简单的用户名/密码认证</td>
</tr>
<tr>
<td>–without-https_autoindex_module</td>
<td>禁用自动索引模块，该模块提供简单的目录浏览功能</td>
</tr>
<tr>
<td>–without-https_geo_module</td>
<td>禁用Geo模块，这个模块可以定义一些变量，这些变量的值将与客户端IP地址关联，这样Nginx针对不同的地区的客户端（根据IP地址判断）返回不一样的结果，例如不同地区显示不同语言的网页</td>
</tr>
<tr>
<td>–without-https_map_module</td>
<td>禁用Map模块，这个模块可以建立一个key/value映射表，不同的key得到相应的value，这样可以针对不同的URL做特殊处理。例如，返回302重定向响应时，可以期望URL不同时返回的Location字段也不一样</td>
</tr>
<tr>
<td>–without-https_split_clients_module</td>
<td>切割客户端IP，该模块会根据客户端的信息，例如IP地址、header头、cookie等，来区分处理，nginx 的 Split Clients（切割客户端IP）的作用是使用 MurmurHash2 哈希算法对客户端的IP进行运算，得到一个32位的整数，这个数值范围从 0~4294967296，匹配不同的区间位置，得到不同的值赋予某个变量。最后根据这变量的不同，作不同的逻辑处理。</td>
</tr>
<tr>
<td>–without-https_referer_module</td>
<td>该模块可以根据请求中的referer字段来拒绝请求</td>
</tr>
<tr>
<td>–without-https_rewrite_module</td>
<td>禁用Rewrite模块，该模块提供HTTP请求在Nginx服务内部的重定向功能，依赖PCRE库</td>
</tr>
<tr>
<td>–without-https_proxy_module</td>
<td>禁用代理模块。该模块提供基本的HTTP反向代理功能</td>
</tr>
<tr>
<td>–without-https_fastcgi_module</td>
<td>禁用FastCGI模块。该模块提供FastCGI功能</td>
</tr>
<tr>
<td>–without-https_uwsgi_module</td>
<td>禁用uwsgi模块。该模块提供uWSGI功能</td>
</tr>
<tr>
<td>–without-https_scgi_module</td>
<td>禁用scqi模块。该模块提供SCGI功能</td>
</tr>
<tr>
<td>–without-https_memcached_module</td>
<td>禁用Memcached模块。该模块可以使得Nginx直接由上游的memcached服务读取数据，并简单地适配成HTTP响应返回给客户端</td>
</tr>
<tr>
<td>–without-https_limit_conn_module</td>
<td>禁用limit_conn_zone模块，该模块针对某个IP地址限制并发连接数。例如，使Nginx对一个IP地址仅允许一个连接。</td>
</tr>
<tr>
<td>–without-https_limit_req_module</td>
<td>禁用Limit Requests模块。该模块针对某个IP地址限制并发请求数</td>
</tr>
<tr>
<td>–without-https_empty_gif_module</td>
<td>禁用Empty Gif模块。该模块可以使得Nginx在收到无效请求时，立刻返回内存中的1×1像素的GIF图片。这种好处在于，对于明显的无效请求不会去试图浪费服务器资源</td>
</tr>
<tr>
<td>–without-https_browser_module</td>
<td>禁用Browser 模块。该模块会根据HTTP请求中的user-agent字段（该字段通常由浏览器填写）来识别浏览器</td>
</tr>
<tr>
<td>–without-https_upstream_hash_module</td>
<td>禁用Upstream模块。该模块用于配置负载均衡结构</td>
</tr>
<tr>
<td>–without-https_upstream_ip_hash_module</td>
<td>禁用Upstream模块 该模块提供当Nginx与后端server建立连接时，会根据IP做散列运算来决定与后端哪台server通信，这样可以实现负载均衡</td>
</tr>
<tr>
<td>–without-https_upstream_least_conn_module</td>
<td>禁用Upstream模块 中的 least 负载均衡算法</td>
</tr>
<tr>
<td>–without-https_upstream_keepalive_module</td>
<td>禁用Upstream模块 中的 keepalive 负载均衡算法</td>
</tr>
<tr>
<td>–with-https_perl_module</td>
<td>需要安装 perl # yum install perl-ExtUtils-Embed | # apt-get install libperl-dev</td>
</tr>
<tr>
<td>–with-perl_modules_path=PATH</td>
<td>perl module放置的路径。只有使用了第三方的perl module，才需要配置这个路径</td>
</tr>
<tr>
<td>–with-perl=PATH</td>
<td>perl binary放置的路径。如果配置的Nginx会执行Perl脚本，那么就必须要设置此路径</td>
</tr>
<tr>
<td>–https-log-path=PATH</td>
<td>access日志放置的位置。每个HTTP请求到结束时都会记录 &lt;prefix&gt;/logs/access.log</td>
</tr>
<tr>
<td>–https-client-body-temp-path=PATH</td>
<td> 处理HTTP请求时如果请求的包体需要暂时存放到临时磁盘文件中，则把这样的临时文件放置到该路径下 &lt;prefix&gt;/client_body_temp </td>
</tr>
<tr>
<td>–https-proxy-temp-path=PATH</td>
<td>Nginx作为HTTP反向代理服务器时，上游服务器产生的HTTP包体在需要临时存放到磁盘文件时，这样的临时文件将放到该路径下 &lt;prefix&gt;/proxy_temp </td>
</tr>
<tr>
<td>–https-fastcgi-temp-path=PATH</td>
<td>Fastcgi所使用临时文件的放置目录 &lt;prefix&gt;/fastcgi_temp</td>
</tr>
<tr>
<td>–https-uwsgi-temp-path=PATH</td>
<td>uWSGI所使用临时文件的放置目录 &lt;prefix&gt;/uwsgi_temp</td>
</tr>
<tr>
<td>–https-scgi-temp-path=PATH</td>
<td>SCGI所使用临时文件的放置目录 &lt;prefix&gt;/scgi_temp</td>
</tr>
<tr>
<td>–without-https</td>
<td>禁用HTTP服务</td>
</tr>
<tr>
<td>–without-https-cache</td>
<td>禁用HTTP 缓冲功能</td>
</tr>
<tr>
<td>–with-mail</td>
<td>开启邮件服务代理(mail server proxy)模块,支 持POP3, IMAP4和SMTP。该功能默认禁用</td>
</tr>
<tr>
<td>–with-mail_ssl_module</td>
<td>开启邮件代理服务对SSL的支持。该功能默认禁用</td>
</tr>
<tr>
<td>–without-mail_pop3_module</td>
<td>在邮件代理下禁用POP3功能。在开启邮件代理模块后该功能默认启用</td>
</tr>
<tr>
<td>–without-mail_imap_module</td>
<td>对邮件代理服务器禁用IMAP4模块，在开启邮件代理模块后该功能默认启用</td>
</tr>
<tr>
<td>–without-mail_smtp_module</td>
<td>对于邮件代理服务器禁用SMTP模块，在开启邮件代理模块后该功能默认启用</td>
</tr>
<tr>
<td>–with-google_perftools_module</td>
<td>Google的针对nginx性能调优的工具，需要安装：yum install gperftools gperftools-devel</td>
</tr>
<tr>
<td>–with-cpp_test_module</td>
<td>C预编译器测试模块</td>
</tr>
<tr>
<td>–add-module=PATH</td>
<td>当在Nginx里加入第三方模块时，通过这个参数指定第三方模块的路径</td>
</tr>
<tr>
<td>–with-cc=PATH</td>
<td>C编译器的路径</td>
</tr>
<tr>
<td>–with-cpp=PATH</td>
<td>C预编译器的路径</td>
</tr>
<tr>
<td>–with-cc-opt=OPTIONS</td>
<td>如果希望在Nginx编译期间指定加入一些编译选项，如指定宏或者使用-I加入某些需要包含的目录，这时可以使用该参数达成目的</td>
</tr>
<tr>
<td>–with-ld-opt=OPTIONS</td>
<td>最终的二进制可执行文件是由编译后生成的目标文件与一些第三方库链接生成的，在执行链接操作时可能会需要指定链接参数，–with-ld-opt就是用于加入链接时的参数。例如，如果我们希望将某个库链接到Nginx程序中，需要在这里加入–with-ld-opt=-llibraryName -LlibraryPath，其中libraryName是目标库的名称，libraryPath则是目标库所在的路径</td>
</tr>
<tr>
<td>–with-cpu-opt=CPU</td>
<td>指定CPU处理器架构，只能从以下取值中选择：pentium、pentiumpro、pentium3、pentium4、athlon、opteron、sparc32、sparc64、ppc64</td>
</tr>
<tr>
<td>–without-pcre</td>
<td>如果确认Nginx不用解析正则表达式，也就是说，nginx.conf配置文件中不会出现正则表达式，那么可以使用这个参数</td>
</tr>
<tr>
<td>–with-pcre</td>
<td>强制使用PCRE库</td>
</tr>
<tr>
<td>–with-pcre=DIR</td>
<td>指定PCRE库的源码位置，在编译Nginx时会进入该目录编译PCRE源码</td>
</tr>
<tr>
<td>–with-pcre-opt=OPTIONS</td>
<td>编译PCRE源码时希望加入的编译选项</td>
</tr>
<tr>
<td>–with-pcre-jit</td>
<td>编译PCRE库支持及时编译</td>
</tr>
<tr>
<td>–with-md5=DIR</td>
<td>指定SHA1库的源码位置，在编译Nginx时会进入该目录编译SHA1源码。 注意：OpenSSL中已经有了SHA1算法的实现。如果已经安装了OpenSSL，那么完全可以使用OpenSSL实现的SHA1算法</td>
</tr>
<tr>
<td>–with-md5-opt=OPTIONS</td>
<td>编译MD5源码时希望加入的编译选项</td>
</tr>
<tr>
<td>–with-md5-asm</td>
<td>使用MD5的汇编源码</td>
</tr>
<tr>
<td>–with-sha1=DIR</td>
<td>指定SHA1库的源码位置，在编译Nginx时会进入该目录编译SHA1源码。 注意：OpenSSL中已经有了SHA1算法的实现。如果已经安装了OpenSSL，那么完全可以使用OpenSSL实现的SHA1算法</td>
</tr>
<tr>
<td>–with-sha1-opt=OPTIONS</td>
<td>编译SHA1源码时希望加入的编译选项</td>
</tr>
<tr>
<td>–with-sha1-asm</td>
<td>使用SHA1的汇编源码</td>
</tr>
<tr>
<td>–with-zlib=DIR</td>
<td>指定zlib库的源码位置，在编译Nginx时会进入该目录编译zlib源码。如果使用了gzip压缩功能，就需要zlib库的支持</td>
</tr>
<tr>
<td>–with-zlib-opt=OPTIONS</td>
<td>编译zlib源码时希望加入的编译选项</td>
</tr>
<tr>
<td>–with-zlib-asm=CPU</td>
<td>指定对特定的CPU使用zlib库的汇编优化功能，目前仅支持两种架构：pentium和pentiumpro</td>
</tr>
<tr>
<td>–with-libatomic</td>
<td>强制使用atomic库。atomic库是CPU架构独立的一种原子操作的实现。它支持以下体系架构：x86（包括i386和x86_64）、PPC64、Sparc64（v9或更高版本）或者安装了GCC 4.1.0及更高版本的架构。</td>
</tr>
<tr>
<td>–with-libatomic=DIR</td>
<td>atomic库所在的位置</td>
</tr>
<tr>
<td>–with-openssl=DIR</td>
<td>指定OpenSSL库的源码位置，在编译Nginx时会进入该目录编译OpenSSL源码。注意：如果Web服务器支持HTTPS，也就是SSL协议，Nginx要求必须使用OpenSSL。</td>
</tr>
<tr>
<td>–with-openssl-opt=OPTIONS</td>
<td>编译OpenSSL源码时希望加入的编译选项</td>
</tr>
<tr>
<td>–with-debug</td>
<td>将Nginx需要打印debug调试级别日志的代码编译进Nginx。这样可以在Nginx运行时通过修改配置文件来使其打印调试日志，这对于研究、定位Nginx问题非常有帮助</td>
</tr>

</tbody></table>

<h4 id="编译安装nginx"><a href="#编译安装nginx" class="headerlink" title="编译安装nginx"></a>编译安装nginx</h4><p>这里和redis的编译安装比较类似，首先在当前目录（/usr/local/nginx-1.19.2）进行编译。输入make即可</p>
<pre class="line-numbers language-c" data-language="c"><code class="language-c">make<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>编译成功之后，就可以安装了，输入以下指令：</p>
<pre class="line-numbers language-c" data-language="c"><code class="language-c">make install<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>ok，安装成功。</p>
<blockquote>
<p> make &amp;&amp; make install</p>
</blockquote>
<h3 id="设置开机启动"><a href="#设置开机启动" class="headerlink" title="设置开机启动"></a>设置开机启动</h3><p>设置nginx开机启动，只需在rc.local增加启动代码即可。</p>
<p><code>vim /etc/rc.local</code></p>
<p>然后在底部增加<code>/usr/local/nginx/sbin/nginx</code></p>
<link rel="stylesheet" href="/css/spoiler.css" type="text/css"><script src="/js/spoiler.js" type="text/javascript" async></script>
    </div>

    
    
    

    <footer class="post-footer">
<div style="padding-top: 26px;">
    

    <div class="endlan">
        <i></i>
        <p>本文结束--- <img src="https://static.xiaosige.com/img/logo.png" style="display:inline-block;margin-bottom:-7px;height: 25px;"> ---感谢您的阅读</p>
    </div>


    <p id="hitokoto" style="text-align:center;margin-top: 30px;font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, STKaiti, KaiTi, SimKai, DFKai-SB, 'Lato', 'PingFang SC', 'Microsoft YaHei', sans-serif;font-weight: bold;color: #999;">
     正在加载一言...
    </p>
    <div style="margin-top: 30px;">
      <img id="wechat_subscriber_qcode" src="https://static.xiaosige.com/img/reward-container-back.png" alt="leeze wechat" style="max-width: 100%;">
    </div>
    

    
</div>


          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    打赏
  </button>
  <div class="post-reward">
      <div>
        <img src="https://static.xiaosige.com/img/wechatpay.png" alt="leeze 微信支付">
        <span>微信支付</span>
      </div>
      <div>
        <img src="https://static.xiaosige.com/img/alipay.png" alt="leeze 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>原文作者： </strong>leeze
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://www.xiaosige.com/post/69813a0e.html" title="Linux安装Nginx--两种方式">https://www.xiaosige.com/post/69813a0e.html</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-CN" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/Nginx/" rel="tag"><i class="fa fa-tag"></i> Nginx</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/36c4e78d.html" rel="prev" title="Nginx一键部署安装脚本">
                  <i class="fa fa-angle-left"></i> Nginx一键部署安装脚本
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/4370af2f.html" rel="next" title="Linux安装Git-两种方式详细教程">
                  Linux安装Git-两种方式详细教程 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="SOHUCS" sid="f649413a93161f7d2172b46baa65e5e6"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Xiaosige.com 版权所有</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">435k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:35</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>



<div calss="ypy" style="text-align:center;display:none;">
    本网站由
    <a target="_blank" rel="nofollow noopener" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" style="border-bottom:none;">
        <img src="https://static.xiaosige.com/img/ypy_logo.png" style="display:inline-block;margin-bottom:-7px;height: 25px;-webkit-filter: brightness(.8);filter: brightness(.8);">
    </a>
    提供CDN加速/云存储服务
</div>


  <div class="beian">
          <img src="https://static.xiaosige.com/img/gongan.png" style="display: inline-block;vertical-align: text-bottom;padding-right: 6px;"><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11011502004362" rel="noopener" target="_blank">京公网安备 11011502004362 </a>
    <span></span><a href="http://beian.miit.gov.cn/" rel="noopener" target="_blank">京ICP备2020038036号-1 </a>
    <span></span>
    本网站由
    <a target="_blank" rel="nofollow noopener" href="https://www.upyun.com/?utm_source=lianmeng&utm_medium=referral" style="border-bottom:none;">
        <img src="https://static.xiaosige.com/img/ypy_logo.png" style="display:inline-block;margin-bottom:-7px;height: 25px;-webkit-filter: brightness(.8);filter: brightness(.8);">
    </a>
    提供CDN加速/云存储服务
  </div>


<link href="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js"></script>
<meting-js server="netease" type="playlist" id="2228518256" fixed="true" autoplay="false" order="random" lrc-type=1  theme="#eb7aab"></meting-js>


<div class="bg-box" id="bg-box1"></div>
<div class="bg-box" id="bg-box2"></div>
<style>
.bg-box {
 background-repeat:no-repeat;
 background-attachment:fixed;
 background-position:50% 50%;
 background-size:cover;
 position:fixed;
 left:0;
 right:0;
 top:0;
 bottom:0
}
#bg-box1 {
 z-index:-998
}
#bg-box2 {
 z-index:-999
}
</style>




    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>
<script class="next-config" data-name="changyan" type="application/json">{"enable":true,"appid":"cyvSPOTJq","appkey":"4436699688bbb9caa6e8826551a7c0f7"}</script>
<script src="/js/third-party/comments/changyan.js" defer></script>
<!-- 提示信息 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-toast-plugin@1.3.2/dist/jquery.toast.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/jquery-toast-plugin@1.3.2/dist/jquery.toast.min.js"></script>
<!-- 樱花特效(https://cdn.jsdelivr.net/gh/yremp/yremp-js@1.5/sakura.js) -->
<!-- 下雪(圣诞) -->

<!-- 天气 -->

<!-- 文字闪烁（变色） -->
<script>
function magicColor(mode,t){
  t=t||10;
  let elem=document.getElementsByClassName("magic-color");
  if(!elem){
      setTimeout(function(){
          magicColor(mode,t-1);
      },400);
      return;
  }
  if(window.mcHandler==undefined){
      window.mcHandler={elements:[]};
      window.mcHandler.colorIndex=0;
      window.mcHandler.run=function(mode){
          let color=mode=="random"?("rgb("+Math.floor(Math.random()*256)+","+Math.floor(Math.random()*256)+","+Math.floor(Math.random()*256)+",1)"):["#CC0000","#9999CC","#CC3366","#669999","#FFCC00","#00CCCC","#CC00CC"][(window.mcHandler.colorIndex++)%7];
          for(var i=0,L=window.mcHandler.elements.length;i<L;i++)window.mcHandler.elements[i].style.color=color;
      }
  }
  window.mcHandler.elements=elem;
  if(window.mcHandler.timer==undefined){
      window.mcHandler.timer=setInterval(()=>{window.mcHandler.run(mode)},500);
  }
}
magicColor("random");//random为随机颜色，否则为固定颜色随机；上方“闪烁（变色）”字样为固定颜色随机
</script>


<!-- 一言API -->
<!-- 现代写法，推荐 -->
<!-- 兼容低版本浏览器 (包括 IE)，可移除 -->
<script src="https://cdn.jsdelivr.net/npm/bluebird@3.7.2/js/browser/bluebird.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fetch@1.1.0/lib/fetch.min.js"></script>
<!--End-->
<script>
fetch('https://v1.hitokoto.cn')
  .then(function (res){
    return res.json();
  })
  .then(function (data) {
    var hitokoto = document.getElementById('hitokoto');
    if(hitokoto){
      hitokoto.innerHTML = "<i class='fa fa-volume-up magic-color' style='margin-right:6px;'></i>" + data.hitokoto + '——【' + data.from + '】';
    }
  })
  .catch(function (err) {
    console.error(err);
  })
</script>


<!-- 代码块自动隐藏 -->
<script>
$(function(){
    const CODE_MAX_HEIGHT = 200;
    const containers = [];

    // 展开
    $('body').on('click', '.js_unfold_code_btn', function () {
        $(this).closest('.js_highlight_container').addClass('on');
    });
    // 收起
    $('body').on('click', '.js_retract_code_btn', function () {
        const $container = $(this).closest('.js_highlight_container').removeClass('on');
        const winTop = $(window).scrollTop();
        const offsetTop = $container.offset().top;
        $(this).css('top', 0);
        if (winTop > offsetTop) {
            // 设置滚动条位置
            $('body, html').animate({
                scrollTop: $container.offset().top - CODE_MAX_HEIGHT
            }, 600);
        }
    });
    // 滚动事件，触发动画效果
    $(window).on('scroll', function () {
        const scrollTop = $(window).scrollTop();
        const temp = [];
        for (let i = 0; i < containers.length; i++) {
            const item = containers[i];
            const { $container, height, $hide, hasHorizontalScrollbar } = item;
            if ($container.closest('body').length === 0) {
                // 如果 $container 元素已经不在页面上, 则删除该元素
                // 防止pjax页面跳转之后，元素未删除
                continue;
            }
            temp.push(item);
            if (!$container.hasClass('on')) {
                continue;
            }
            const offsetTop = $container.offset().top;
            const hideBtnHeight = $hide.outerHeight();
            // 减去按钮高度，减去底部滚动条高度
            const maxTop = parseInt(height - (hasHorizontalScrollbar ? 17 : 0) - hideBtnHeight);
            let top = parseInt(
                Math.min(
                    Math.max(scrollTop - offsetTop, 0), // 如果小于 0 ，则取 0
                    maxTop,// 如果大于 height ，则取 height
                )
            );
            // 根据 sin 曲线设置"收起阅读"位置
            const halfHeight = parseInt($(window).height() / 2 * Math.sin((top / maxTop) * 90 * (2 * Math.PI/360)));
            $hide.css('top', Math.min(top + halfHeight, maxTop));
        }
        //containers = temp;
    });

    // 添加隐藏容器
    const addCodeWrap = ($node) => {
        const $container = $node.wrap('<div class="js_highlight_container highlight-container"><div class="highlight-wrap"></div></div>').closest('.js_highlight_container');

        // 底部 "阅读更多" 与 侧边栏 "收起阅读"
        const $btn = $(`
        <div class="highlight-footer">
          <a class="js_unfold_code_btn show-btn" href="javascript:;">
              <span class="btn-inner">
                阅读更多<i class="fa fa-angle-right fa-lg" aria-hidden="true"></i>
              </span>
              <div class="btnbg-x"></div>
          </a>
        </div>
        <a class="js_retract_code_btn hide-btn" href="javascript:;"><i class="fa fa-angle-up fa-lg" aria-hidden="true"></i>收起阅读</a>
      `);

        $container.append($btn);
        return $container;
    };

    $('.highlight').each(function () {
        // 防止重复渲染
        if (this.__render__ === true) {
            return true;
        }
        this.__render__ = true;
        const $this = $(this);
        const height = $(this).outerHeight();
        if (height > CODE_MAX_HEIGHT) {
            // 添加展开&收起容器
            const $container = addCodeWrap($this, height);
            containers.push({
                $container,
                height,
                $hide: $container.find('.js_retract_code_btn'),
                hasHorizontalScrollbar: this.scrollWidth > this.offsetWidth,
            });
        }
    });

    $('.line-numbers').each(function () {
        // 防止重复渲染
        if (this.__render__ === true) {
            return true;
        }
        this.__render__ = true;
        const $this = $(this);
        const height = $(this).outerHeight();
        if (height > CODE_MAX_HEIGHT) {
            // 添加展开&收起容器
            const $container = addCodeWrap($this, height);
            containers.push({
                $container,
                height,
                $hide: $container.find('.js_retract_code_btn'),
                hasHorizontalScrollbar: this.scrollWidth > this.offsetWidth,
            });
        }
    });

    $('.table-container').each(function () {
        // 防止重复渲染
        if (this.__render__ === true) {
            return true;
        }
        this.__render__ = true;
        const $this = $(this);
        const height = $(this).outerHeight();
        if (height > CODE_MAX_HEIGHT) {
            // 添加展开&收起容器
            const $container = addCodeWrap($this, height);
            containers.push({
                $container,
                height,
                $hide: $container.find('.js_retract_code_btn'),
                hasHorizontalScrollbar: this.scrollWidth > this.offsetWidth,
            });
        }
    });

});
</script>


<script  type="text/javascript">

layui.use(['jquery', 'layer'], function(){

  var $ = layui.$,layer = layui.layer;

  <!-- wobble窗口摆动特效 -->
  


     var wobbleWindow = function(object, params) {
          var canvas,
              ctx;
          var mousePos = {
              x: 0,
              y: 0
          };
          var isResizing = false;
          var delayId = 0;
          var canvasContent = {};
          var points = {};

          var settings = {};
          settings.name = 'wobblew'; //name
          settings.position = 'relative'; //relative or absolute
          settings.depth = -1; //depth for zIndex
          settings.overflowX = 'visible';
          settings.overflowY = 'visible';
          settings.offsetX = 0; //+ or - value the size of the div
          settings.offsetY = 0; //+ or - value the size of the div
          settings.moveTypeIn = 'move'; //method points follow the mouse
          settings.moveTypeOut = 'wobble'; //method points go back to init position
          settings.wobbleFactor = 0.95; //control the wobble effect
          settings.wobbleSpeed = 0.1; //control the wobble effect
          settings.moveSpeed = 6; //control the move speed
          settings.lineWidth = 1; //lineWidth

          settings.transplantLineColor = false; //true Use Object border-color
          settings.lineColor = ''; //no value = no line. Use hex/rgba values
          settings.transplantBodyColor = true; //true Use Object background Color
          settings.bodyColor = ''; //no value = no body color. Use hex/rgba values
          settings.radius = 50; //
          settings.pointCountX = 7; //quantity of points horizontal. must be an odd int
          settings.pointCountY = 5; //quantity of points vertical. must be an odd int
          settings.movementLeft = true; //enable/disable movement directions
          settings.movementRight = true; //enable/disable movement directions
          settings.movementTop = true; //enable/disable movement directions
          settings.movementBottom = true; //enable/disable movement directions
          settings.autoResize = true; //if true size will be automatically adjusted
          settings.debug = false; //enable/disable debug mode

          // ---
          if (params !== undefined) {
              for (var prop in params) {
                  if (params.hasOwnProperty(prop) && settings.hasOwnProperty(prop)) {
                      settings[prop] = params[prop];
                  }
              }
          }

          // ---
          if (!object) {
              throw Error('\n' + 'No div element found');
          }
          if ((settings.pointCountX % 2) === 0) {
              throw Error('\n' + 'Param pointCountX must be an odd integer');
          }
          if ((settings.pointCountY % 2) === 0) {
              throw Error('\n' + 'Param pointCountY must be an odd integer');
          }

          // ---
          HTMLElement.prototype.__defineGetter__("currentStyle", function() {
              return this.ownerDocument.defaultView.getComputedStyle(this, null);
          });
          // ---
          function init() {
              canvas = document.createElement('canvas');
              canvas.id = settings.name;
              canvas.style.position = 'absolute';
              canvas.style.zIndex = settings.depth.toString();
              canvas.addEventListener('mousemove', mouseMoveHandler);
              canvas.addEventListener('mouseleave', mouseLeaveHandler);
              ctx = canvas.getContext('2d');

              // element.insertBefore(canvas, element.firstChild);
              object.appendChild(canvas);
              object.style.position = settings.position;
              object.style.zIndex = (settings.depth + 1).toString();
              if (settings.overflowX.length > 0) {
                  object.parentElement.style.overflowX = settings.overflowX;
              };
              if (settings.overflowY.length > 0) {
                  object.parentElement.style.overflowY = settings.overflowY;
              };
              if (settings.transplantBodyColor) {
                  if (object.currentStyle.backgroundColor.length > 0) {
                      settings.bodyColor = object.currentStyle.backgroundColor;
                  }
              };
              if (settings.transplantLineColor) {
                  if (object.currentStyle.borderColor.length > 0) {
                      settings.lineColor = object.currentStyle.borderColor;
                  }
              };
              canvasContent.elementWidth = object.offsetWidth;
              canvasContent.elementHeight = object.offsetHeight;
              // ---
              resizeCanvas();
              addWindow();
              animloop();
              // -----------
              if (settings.transplantBodyColor) {
                  if (object.currentStyle.backgroundColor.length > 0) {
                      if (object.className.length > 0) {
                          object.className += ' wobbleTransparentBK';
                      } else {
                          object.className = ' wobbleTransparentBK';
                      };
                  }
              };
              if (settings.transplantLineColor) {
                  if (object.currentStyle.borderColor.length > 0) {
                      if (object.className.length > 0) {
                          object.className += ' wobbleTransparentLine';
                      } else {
                          object.className = ' wobbleTransparentLine';
                      };
                  }
              };
          };

          // ---
          function resizeCanvas() {
              canvasContent.width = canvasContent.elementWidth + settings.offsetX * 2;
              canvasContent.height = canvasContent.elementHeight + settings.offsetY * 2;

              if (settings.radius > 0) { //round,  ceil
                  settings.pointCountX = Math.round(canvasContent.width / settings.radius);
                  settings.pointCountY = Math.round(canvasContent.height / settings.radius);
              };
              if (settings.pointCountX % 2 == 0) {
                  settings.pointCountX = settings.pointCountX + 1;
              };
              if (settings.pointCountY % 2 == 0) {
                  settings.pointCountY = settings.pointCountY + 1;
              };

              points.spaceX = Math.min(canvasContent.elementWidth, canvasContent.width / (settings.pointCountX - 1));
              points.spaceY = Math.min(canvasContent.elementHeight, canvasContent.height / (settings.pointCountY + 1));
              points.radius = Math.ceil(Math.max(points.spaceX, points.spaceY));

              ///--------------new1------------------
              canvasContent.left = 0;
              canvasContent.top = 0;
              settings.canvasWidth = canvasContent.elementWidth;
              if (settings.movementLeft) {
                  canvas.style.left = -points.radius + 'px';
                  settings.canvasWidth += points.radius;
                  canvasContent.left = points.radius - settings.offsetX;
              } else {
                  canvas.style.left = -settings.offsetX + 'px';
              };
              if (settings.movementRight)
                  settings.canvasWidth += points.radius;

              settings.canvasHeight = canvasContent.elementHeight;
              if (settings.movementTop) {
                  canvas.style.top = -points.radius + 'px';
                  settings.canvasHeight += points.radius;
                  canvasContent.top = points.radius - settings.offsetY;
              } else {
                  canvas.style.top = -settings.offsetY + 'px';
              };
              if (settings.movementBottom)
                  settings.canvasHeight += points.radius;

              canvas.width = settings.canvasWidth;
              canvas.height = settings.canvasHeight;
          };

          // ---
          function addWindow() {
              points.pointHolder = [];
              // ---
              var point;
              var flag;
              var i,
                  l;
              // ---
              //top
              flag = true;
              for (i = 0, l = settings.pointCountX; i < l; i++) {
                  if (settings.movementTop) {
                      if (flag) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top, 0, 0, 0, true, points.spaceX, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top, 0, 0, 0, true, points.spaceX, 'C', settings.debug);
                          flag = true;
                      }
                      if (i === 0 || i === l - 1) {
                          point.color = '#00FF00';
                          point.movement = false;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 0 || i === l - 1) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }

              // ---
              //right
              flag = false;
              for (i = 1, l = settings.pointCountY + 1; i < l; i++) {
                  if (settings.movementRight) {
                      if (flag) {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'C', settings.debug);
                          flag = true;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 1) {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + (i - 1) * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      } else if (i === settings.pointCountY) {
                          point = addPoint(canvasContent.left + canvasContent.width, canvasContent.top + (i + 1) * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }

              // ---
              //bottom
              flag = true;
              for (i = settings.pointCountX - 1, l = -1; i > l; i--) {
                  if (settings.movementBottom) {
                      if (flag) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top + canvasContent.height, 0, 0, 0, true, points.spaceX, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top + canvasContent.height, 0, 0, 0, true, points.spaceX, 'C', settings.debug);
                          flag = true;
                      }
                      if (i === 0 || i === settings.pointCountX - 1) {
                          point.color = '#00FF00';
                          point.movement = false;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 0 || i === settings.pointCountX - 1) {
                          point = addPoint(canvasContent.left + i * points.spaceX, canvasContent.top + canvasContent.height, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }

              // ---
              //left
              flag = false;
              for (i = settings.pointCountY, l = -1; i > l; i--) {
                  if (settings.movementLeft) {
                      if (flag) {
                          point = addPoint(canvasContent.left, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'P', settings.debug);
                          flag = false;
                      } else {
                          point = addPoint(canvasContent.left, canvasContent.top + i * points.spaceY, 0, 0, 0, true, points.spaceY, 'C', settings.debug);
                          flag = true;
                      }
                      points.pointHolder.push(point);
                  } else {
                      if (i === 0) {
                          point = addPoint(canvasContent.left, canvasContent.top + i * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      } else if (i === settings.pointCountY) {
                          point = addPoint(canvasContent.left, canvasContent.top + (i + 1) * points.spaceY, 0, 0, 0, false, 0, 'P', settings.debug);
                      }
                      points.pointHolder.push(point);
                  }
              }
          }

          // ---
          function addPoint(x, y, xp, yp, distance, movement, radius, type, visible) {
              var point = {};
              point.x = x;
              point.y = y;
              point.xp = x;
              point.yp = y;
              point.sx = 0;
              point.sy = 0;
              point.distance = distance;
              point.movement = movement;
              point.radius = radius;
              point.type = type;
              point.visible = visible;
              return point;
          };

          // ---
          window.requestAnimFrame = (function() {
              return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) {
                  window.setTimeout(callback, 1000 / 60);
              };
          })();

          function animloop() {
              requestAnimFrame(animloop);
              render();
              if (settings.autoResize) {
                  resize();
              }
          };

          // ---
          function render() {
              ctx.clearRect(0, 0, settings.canvasWidth, settings.canvasHeight);

              // ---
              var windowPoints = points.pointHolder;
              var i,
                  l;

              // ---
              ctx.beginPath();
              ctx.moveTo(windowPoints[0].x, windowPoints[0].y);
              for (i = 1, l = windowPoints.length; i < l; i += 2) {
                  var point = windowPoints[i];

                  // ---
                  var dx = mousePos.x - point.xp;
                  var dy = mousePos.y - point.yp;
                  point.distance = Math.sqrt(dx * dx + dy * dy);
                  if (point.distance < point.radius) {
                      if (settings.moveTypeIn === 'wobble') {
                          point.sx = point.sx * settings.wobbleFactor + (mousePos.x - point.x) * settings.wobbleSpeed;
                          point.sy = point.sy * settings.wobbleFactor + (mousePos.y - point.y) * settings.wobbleSpeed;
                          point.x = point.x + point.sx;
                          point.y = point.y + point.sy;
                      } else if (settings.moveTypeIn === 'move') {
                          point.x -= (point.x - mousePos.x) / settings.moveSpeed;
                          point.y -= (point.y - mousePos.y) / settings.moveSpeed;
                      }
                  } else {
                      if (settings.moveTypeOut === 'wobble') {
                          point.sx = point.sx * settings.wobbleFactor + (point.xp - point.x) * settings.wobbleSpeed;
                          point.sy = point.sy * settings.wobbleFactor + (point.yp - point.y) * settings.wobbleSpeed;
                          point.x = point.x + point.sx;
                          point.y = point.y + point.sy;
                      } else if (settings.moveTypeOut === 'move') {
                          point.x -= (point.x - point.xp) / settings.moveSpeed;
                          point.y -= (point.y - point.yp) / settings.moveSpeed;
                      }
                  }

                  // ---
                  var pointBefor = windowPoints[i - 1];
                  var pointAfter = windowPoints[i + 1];
                  if (i > 2 && i < windowPoints.length - 2) {
                      if (pointBefor.movement) {
                          pointBefor.x = (windowPoints[i - 2].x + point.x) / 2;
                          pointBefor.y = (windowPoints[i - 2].y + point.y) / 2;
                      }
                      if (pointAfter.movement) {
                          pointAfter.x = (windowPoints[i + 2].x + point.x) / 2;
                          pointAfter.y = (windowPoints[i + 2].y + point.y) / 2;
                      }
                  }
                  ctx.quadraticCurveTo(point.x, point.y, pointAfter.x, pointAfter.y);
              }

              // ---
              if (settings.lineColor.length > 0) {
                  ctx.lineWidth = settings.lineWidth;
                  ctx.strokeStyle = settings.lineColor;
                  ctx.stroke();
              }
              if (settings.bodyColor.length > 0) {
                  ctx.fillStyle = settings.bodyColor;
                  ctx.fill();
              }
              // ctx.globalCompositeOperation = 'source-out';
              // ctx.fillStyle = "rgba(0, 0, 0, 1)";
              // ctx.fill();

              // ---
              if (settings.debug) {
                  for (i = 0, l = windowPoints.length; i < l; i++) {
                      var point = windowPoints[i];
                      if (point.visible) {
                          if (point.type === 'P') {
                              drawCircle(point.x, point.y, 3, '#FF0000');
                          } else {
                              drawCircle(point.x, point.y, 6, '#FF00FF');
                          }
                          if (point.color) {
                              drawCircle(point.x, point.y, 12, point.color);
                          }
                      }
                  }
                  ctx.strokeStyle = '#000000';
                  ctx.strokeRect(0, 0, settings.canvasWidth, settings.canvasHeight);
              }
          };

          // ---
          function delayFlag() {
              resizeCanvas();
              addWindow();
              isResizing = false;
          };

          function resize() {
              if (!isResizing) {
                  if (canvasContent.elementWidth !== object.offsetWidth || canvasContent.elementHeight !== object.offsetHeight) {
                      // -----------
                      isResizing = true;
                      canvasContent.elementWidth = object.offsetWidth;
                      canvasContent.elementHeight = object.offsetHeight;
                      // 防止闪白
                      delayId = window.setTimeout(delayFlag, 10);
                  }
              }
          };

          // ---
          function drawCircle(x, y, radius, color) {
              ctx.beginPath();
              ctx.arc(x, y, radius, 0, 2 * Math.PI);
              ctx.strokeStyle = color;
              ctx.stroke();
          };

          // ---
          function mouseMoveHandler(event) {
              mousePos = getMousePos(canvas, event);
          };

          function mouseLeaveHandler(event) {
              mousePos.x = -10000;
              mousePos.y = -10000;
          };

          // ---
          function getMousePos(canvas, event) {
              var rect = canvas.getBoundingClientRect();
              return {
                  x: event.clientX - rect.left,
                  y: event.clientY - rect.top
              };
          };

          // ---
          init();
      };


  var settings = {
        radius: 20,
        wobbleFactor: 0.98,
        wobbleSpeed: 0.05,
        moveSpeed: 3,
        lineWidth: 3,
        lineColor: '#000',
        bodyColor: '#EEE'

  };
/*
  var footers=document.querySelectorAll(".footer");
  wobbleWindow(footers[footers.length-1],{
                radius: 20,
                depth:-2,
                movementBottom: false,
                movementLeft: false,
                movementRight: false,
                debug: false
  });*/

  var postblocks=document.querySelectorAll(".main-inner .post-block ");
  [].forEach.call(postblocks, function(elm) {
      wobbleWindow(elm,settings);
  });

  

});

</script>


<!-- 页面背景图片动态加载 -->
<script>

     //获取指定长度的uuid
     function uuid(len, radix) {
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        var uuid = [], i;
        radix = radix || chars.length;

        if (len) {
          // Compact form
          for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
        } else {
          // rfc4122, version 4 form
          var r;

          // rfc4122 requires these characters
          uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
          uuid[14] = '4';

          // Fill in random data.  At i==19 set the high bits of clock sequence as
          // per rfc4122, sec. 4.1.5
          for (i = 0; i < 36; i++) {
            if (!uuid[i]) {
              r = 0 | Math.random()*16;
              uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
            }
          }
        }

        return uuid.join('');
    }

    function animatechangbgimg(elm,opacityvalue,bgimgurl){
        $(elm).animate(
        　　{opacity:opacityvalue},
        　　"slow",
        　　null,
        　　function(){
               $(elm).css("background-image","url("+bgimgurl+")");
        　　}
        );
    }

    function checktime(time){
        var oldtime = localStorage.getItem("pjax-imgurl-leeze-lastvisitedtime");
        return Math.floor(((new Date).getTime()-oldtime)/1e3) >= time;
    }

    function changbgimgurl(){

          if(checktime(13)){//每次打开新页面，都会触发一个新的调度器，固加入lastvisitedtime校验，确保循环时间
                //var tc = "https://cdn.jsdelivr.net/gh/maplesugarr/blog-assets/imgs/body-bg/body-bg-" + Math.floor(23 * Math.random()) + ".jpg";
                //var bgimgurl = 'https://source.unsplash.com/collection/30327996/2000x1000';
                //var initbgurl = null,newbgurl = "https://cdn.jsdelivr.net/gh/leeze2012/blog-assets/img/body-bg-" + Math.floor(26 * Math.random()) + ".jpg";
                var initbgurl = null,newbgurl = "https://static.xiaosige.com/img/bg/body-bg-" + Math.floor(26 * Math.random()) + ".jpg";
                if(localStorage.hasOwnProperty('pjax-imgurl-leeze')){
                  initbgurl = localStorage.getItem("pjax-imgurl-leeze");
                }else{
                  initbgurl = newbgurl;
                }

                if($("#bg-box1").css('opacity')==="1"){
                      animatechangbgimg("#bg-box1",0,newbgurl);
                      animatechangbgimg("#bg-box2",1,initbgurl);
                }else{
                      animatechangbgimg("#bg-box1",1,initbgurl);
                      animatechangbgimg("#bg-box2",0,newbgurl);
                }

                localStorage.setItem("pjax-imgurl-leeze", newbgurl);
                localStorage.setItem("pjax-imgurl-leeze-lastvisitedtime",(new Date).getTime());
          }

    };

    setInterval(changbgimgurl,15000);

</script>

<!-- 标题文字闪烁效果 -->
<script>

document.getElementsByClassName('site-title')[0].setAttribute('data-splitting','chars');

Splitting();
gsap.set('.char', {
  '--hue': gsap.utils.distribute({
    base: 0,
    amount: 330,
  })
});
gsap.to('.char', {
  '--weight': 700,
  '--saturation': 80,
  ease: 'sine.inOut',
  duration: 0.5,
  stagger: {
    yoyo: true,
    repeat: -1,
    each: 0.15,
  }
}).time(2);
</script>


<script type="text/javascript">
    $(document).ready(function() {
        <!-- 站点作者头像 -->
        if($('.site-author:first').children().first().prop("tagName").toLowerCase() === "img"){
            <!-- 头像站点作者头像连接到关于我 -->
            $('.site-author-image').prop('outerHTML', "<a href='/about' title='关于我'>"+$('.site-author-image').prop("outerHTML")+"</a>");
            <!-- 站点作者头像动画阴影 -->
            $(".site-author-image").hover(function(){
                $(this).toggleClass('site-author-image-yy');
            },function(){
                $(this).toggleClass('site-author-image-yy');
            });
        }
        <!-- 五星好评 -->
        if($("#wpac-rating").length > 0){
            $("#wpac-rating").before("<div style='color: rgba(0, 0, 0, 0.75); font-size:13px; letter-spacing:3px'>(&gt; 看完记得五星好评哦亲 &lt;)</div>");
            $(".wp_rating").css("height","30px");
        }
        if($(".copyright").length > 0){
            <!-- footer追加邮箱 -->
            if($(".leezeEmail").length === 0){
                $(".copyright").append("<span class='leezeEmail post-meta-item'><i style='margin-right:6px;' class='fa fa-fw fa-envelope with-love'></i><a href='mailto:leeze0216@163.com' title='E-Mail → mailto:leeze0216@163.com' target='_blank'>leeze0216@163.com</a></span>");
            }
            <!-- 版权图标 -->
            $(".copyright span[class='with-love']").css("display","none");
        }
        <!-- footer的阅读次数位置调整 -->
        if($(".busuanzi-count").length > 0){
            $(".wordcount").append($(".busuanzi-count").html());
            $(".busuanzi-count").remove();
        }
        <!-- 标签页追加抖动样式 -->
        if($('.tag-cloud-tags a').length > 0){
            $('.tag-cloud-tags a').each(function(){
              $(this).addClass('shake shake-slow');
            });
        }
        <!-- 社交链接增加hover样式 -->
        if($('.links-of-author-item a').length > 0){
            $('.links-of-author-item a').each(function(index,element){
                if((index+1)%2 === 1){
                    $(this).addClass('hvr-bounce-to-right');
                }else{
                    $(this).addClass('hvr-bounce-to-left');
                }
                if($(this).children('i').length > 0){
                    $(this).children('i').addClass('faa-spin');
                }
            });
        }
        <!-- 主菜单hover样式 -->
        if($('.main-menu .menu-item a').length > 0){
            $('.main-menu .menu-item a').each(function(index,element){
                $(this).addClass('hvr-grow-shadow');
                if($(this).children('i').length > 0){
                    $(this).children('i').addClass('faa-wrench');
                }
            });
        }
        <!-- 移动端 隐藏音乐 -->
        if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) {
            $('meting-js').css('display','none');
        }

        <!-- 转载 -->
        if($('.zhuanzai').length > 0){
            $('.zhuanzai').each(function(index,element){
                $(this).hover(function(){
                    var tipmsg = this.getAttribute('href');
                    if( tipmsg === 'javascript:;'){
                        tipmsg = "抱歉，忘记转载地址了！";
                    }
                    layer.tips(tipmsg, $(this), {
                      tips: 3
                    });
                },function(){
                    layer.closeAll('tips');
                });
            });
        }

    });
</script>
<!-- 自定义 -->
<script src="/zone/js/leeze.js"></script>
<div class="moon-menu">
  <div class="moon-menu-items">
    
    <div id="moon-menu-item-back2bottom" class="moon-menu-item" onclick="back2bottom()">
      <i class='fa fa-chevron-down'></i>    </div>
    
    <div id="moon-menu-item-back2top" class="moon-menu-item" onclick="back2top()">
      <i class='fa fa-chevron-up'></i>    </div>
    
  </div>
  <div class="moon-menu-button">
    <svg class="moon-menu-bg">
      <circle class="moon-menu-cricle" cx="50%" cy="50%" r="44%"></circle>
      <circle class="moon-menu-border" cx="50%" cy="50%" r="48%"></circle>
    </svg>
    <div class="moon-menu-content">
      <div class="moon-menu-icon"><i class='fas fa-ellipsis-v'></i></div>
      <div class="moon-menu-text"></div>
    </div>
  </div>
</div><script src="/js/injector.js"></script><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</body>
</html>
